﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ZD_Domain;
using ZD_Entities;

namespace ZD_Repositories
{
    public class UnitOfWork : IDisposable
    {


        private NewBeautyContext _NewBeautyContext;
        private RepositoryBase<tb_ImageInfo> _tb_ImageInfoRepository;
        private RepositoryBase<tb_Boards> _tb_BoardsRepository;
        private RepositoryBase<tb_Member> _tb_MemberRepository;

        public UnitOfWork()
        {
            this._NewBeautyContext = new NewBeautyContext();
        }

        #region NewBeautyContext
        public RepositoryBase<tb_ImageInfo> tb_ImageInfoRepository
        {
            get
            {
                if (this._tb_ImageInfoRepository == null)
                    _tb_ImageInfoRepository = new RepositoryBase<tb_ImageInfo>(this._NewBeautyContext);

                return _tb_ImageInfoRepository;
            }
        }

        public RepositoryBase<tb_Boards> tb_BoardsRepository
        {
            get
            {
                if (this._tb_BoardsRepository == null)
                    _tb_BoardsRepository = new RepositoryBase<tb_Boards>(this._NewBeautyContext);

                return _tb_BoardsRepository;
            }
        }

        public RepositoryBase<tb_Member> tb_MemberRepository
        {
            get
            {
                if (this._tb_MemberRepository == null)
                    _tb_MemberRepository = new RepositoryBase<tb_Member>(this._NewBeautyContext);

                return _tb_MemberRepository;
            }
        }
        #endregion


        public int Save()
        {
            return this._NewBeautyContext.SaveChanges();
        }

        public void Dispose()
        {
            if (_NewBeautyContext != null)
                _NewBeautyContext.Dispose();
        }

    }
}
